﻿using Compass.Wasm.Shared;
using Compass.Wasm.Shared.Categories;

namespace Compass.Wpf.ApiServices.Categories;

public interface IMaterialItemService : IBaseService<MaterialItemDto>
{
    Task<ApiResponse<MaterialItemDto>> GetFirstOrDefaultByTypeAsync(string type);
    Task<ApiResponse<MaterialItemDto>> GetFirstOrDefaultByMtlNumberAsync(string mtlNumber);
}

public class MaterialItemService:BaseService<MaterialItemDto>,IMaterialItemService
{
    #region ctor
    private readonly HttpRestClient _client;
    private const string ServiceName = "MaterialItem";
    public MaterialItemService(HttpRestClient client) : base(client, ServiceName)
    {
        _client = client;
    }
    #endregion

    #region 扩展
    
    public async Task<ApiResponse<MaterialItemDto>> GetFirstOrDefaultByTypeAsync(string type)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/Type?type={type}"
        };
        return await _client.ExecuteAsync<MaterialItemDto>(request);
    }
    public async Task<ApiResponse<MaterialItemDto>> GetFirstOrDefaultByMtlNumberAsync(string mtlNumber)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/MtlNumber?mtlNumber={mtlNumber}"
        };
        return await _client.ExecuteAsync<MaterialItemDto>(request);
    }

    #endregion
}